#ifndef __SOCKET_H__
#define __SOCKET_H__

#include <sys/socket.h>
#include <map>
#include <memory>
#include "buffer.h"

class Socket
{  
public:
    typedef std::shared_ptr<Socket> ptr;

    Socket();
    Socket(int fd);
    ~Socket();

    //绑定
    int Bind(const char* ip, int port);

    int Listen(int que_num);

    int Receive();

    int Send();

    //得到fd
    int GetFd() const;

    //将该Socket设置为非阻塞
    int SetNonBlocking();

    //将该Socket添加到epoll中
    void AddToEpoll(int epollfd, bool enable_et);

    //将该Socket从epoll中移除
    void RemoveFromEpoll(int epollfd);

    Buffer::ptr& GetRecvBuf();

    Buffer::ptr& GetSendBuf();
private:
    int m_fd;
    Buffer::ptr m_recvBuf;
    Buffer::ptr m_sendBuf;
};
#endif // !__SOCKET_H__
